<?php
/**
*
* @package phpBB3
* @version $Id$
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
*/

/**
* @ignore
*/
 
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include_once($phpbb_root_path . 'common.' . $phpEx);
include_once($phpbb_root_path . 'sv_common.' . $phpEx);
$in_fb_iframe = true;

// Basic parameter data
$followee_user_id		= request_var('followee_user_id', '');

$code = $_REQUEST['code'];

//if ($code != '')
if (false)
{
	$app_id = get_fb_app_id();
	$app_url = get_fb_app_url();
	$app_secret = get_fb_app_secret();
		
	$url = 'https://graph.facebook.com/oauth/access_token?client_id='. $app_id . '&redirect_uri=' . urlencode($app_url) . '&client_secret=' . $app_secret . '&code=' . $code ;
	$ans = file_get_contents($url);
	
	if ($ans)
	{
    	$graph_url = "https://graph.facebook.com/me?" . $ans;
    	$info = json_decode(file_get_contents($graph_url));
   	
    	print_r($info);
	}
}
echo "followee_user_id : $followee_user_id";

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('stockvirtual');

$user_id 	= $user->data['user_id'];
echo " user id:$user_id";

if ($followee_user_id != '' && $user_id != ANONYMOUS)
{
	$followee_user_id	= (int)$followee_user_id;
	
	// add follower/followee pairs.
	$sql = 'INSERT IGNORE INTO sv_follow_user_list SET followee_user_id=' . $followee_user_id . ', follower_user_id=' . $user_id;
    echo "    $sql\n";
    $result	= $db->sql_query($sql); 
    
    
    // refresh
//	$url = append_sid("{$phpbb_root_path}/fb/index.$phpEx", '');
//	redirect($url, false, true);
//	echo "<a href='" . $url . "'>Redirecting...</a><br /><br />" . $url;		
}
else
{
	// redirect to index page as the important parameter is not provided.
	//echo("<script> top.location.href='index.php'</script>");	
	// refresh
//	$url = append_sid("{$phpbb_root_path}/fb/index.$phpEx", '');
//	redirect($url, false, true);
//	echo "<a href='" . $url . "'>Redirecting...</a><br /><br />" . $url;
}

?>